package com.example.accessibilityhelper.util

import android.accessibilityservice.AccessibilityService
import android.os.Bundle
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo


fun AccessibilityNodeInfo.findAccessibilityNodeByShortViewId(id: String): MutableList<AccessibilityNodeInfo> {
    val realId = "com.tencent.wework:id/$id"
    return this.findAccessibilityNodeInfosByViewId(realId)
}

fun AccessibilityNodeInfo.click() {
    performAction(AccessibilityNodeInfo.ACTION_CLICK)
}

fun AccessibilityNodeInfo.gestureClick(service: AccessibilityService) {
    AccessibilityUtils.clickByGesture(service, this)
}

fun AccessibilityNodeInfo.fill(text: String) {
    this.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, Bundle().apply {
        putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text)
    })
}

fun AccessibilityEvent.isWindowStateChanged(): Boolean {
    return this.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
}

fun AccessibilityNodeInfo.findByViewId(id:String): MutableList<AccessibilityNodeInfo>? {
    return this.findAccessibilityNodeInfosByViewId(id)
}